package com.yidu.t299.dao.zzy;

import com.yidu.t299.domain.zzy.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.lang.Class;
import java.util.List;

/**
 * @Author:周子怡
 * @Date:2023/03/16/11:00
 * @Description:
 */
@Mapper
public interface SyllabusMapper {
    /**
     * 按主键查询
     * @param syllabusId 主键
     * @return 成绩对象
     */
    @Select({
            "select",
            " syllabus_id, syllabus_date, AM_PM, week_name,lesson_id,classroom_id,class_id,record_id",
            " from syllabus",
            " where syllabus_id = #{syllabusId,jdbcType=INTEGER}"
    })
    @Results(id = "SyllabusMap",value = {
            @Result(column = "syllabus_id", property = "syllabusId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "syllabus_date", property = "syllabusDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "AM_PM", property = "amPm", jdbcType = JdbcType.VARCHAR),
            @Result(column = "week_name", property = "weekName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "lesson_id", property = "lessonId", jdbcType = JdbcType.INTEGER),
            @Result(column = "classroom_id", property = "classroomId", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id", property = "classId", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.INTEGER)
    })
    Syllabus selectByPrimaryKey(Integer syllabusId);

    /**
     * 按条件分页查询创建数据集合
     *
     * @param rows      每页的行数
     * @param page      页码
     * @param condition 条件参数
     * @return 成绩对象集合
     */
    @Select("SELECT * FROM syllabus sb " +
            "JOIN class c " +
            "ON sb.class_id=c.class_id " +
            "JOIN classRoom r " +
            "ON sb.classroom_id=r.classRoom_id " +
            "JOIN lesson s " +
            "ON sb.lesson_id=s.lesson_id " +
            "JOIN record d " +
            "ON sb.lesson_id=d.record_id " +
            "where 1=1 ${condition} limit #{page},#{rows}")
    @Results({
            @Result(column = "syllabus_id", property = "syllabusId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "syllabus_date", property = "syllabusDate", jdbcType = JdbcType.VARCHAR),
            @Result(column = "AM_PM", property = "amPm", jdbcType = JdbcType.VARCHAR),
            @Result(column = "week_name", property = "weekName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "lesson_id", property = "lessonId", jdbcType = JdbcType.INTEGER),
            @Result(column = "classroom_id", property = "classroomId", jdbcType = JdbcType.INTEGER),
            @Result(column = "class_id", property = "classId", jdbcType = JdbcType.INTEGER),
            @Result(column = "record_id", property = "recordId", jdbcType = JdbcType.INTEGER),
            @Result(column = "lesson_name", property = "lessonName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "class_name", property = "className", jdbcType = JdbcType.VARCHAR),
            @Result(column = "classRoom_name", property = "classRoomName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "record_name", property = "recordName", jdbcType = JdbcType.VARCHAR),

    })
    List<Syllabus> selectByPage(@Param("rows") int rows, @Param("page") int page, @Param("condition") String condition);

    /**
     * 按条件查询grade表中数据行数，因为涉及到了多表，所以这里也需要多表联查，不然无法设置条件
     *
     * @param condition 条件参数
     * @return 数据行数
     */
    @Select("SELECT count(*) FROM syllabus sb " +
            "JOIN class c " +
            "ON sb.class_id=c.class_id " +
            "JOIN classRoom r " +
            "ON sb.classroom_id=r.classRoom_id " +
            "JOIN lesson s " +
            "ON sb.lesson_id=s.lesson_id " +
            "JOIN record d " +
            "ON sb.lesson_id=d.record_id " +
            "where 1=1 ${condition}")
    int selectCount(@Param("condition") String condition);


    //////////////////////////////////////////////////////////////////////////
    // 如下是扩展的方法，主要在添加/修改之前进行一些查询操作，比如说根据名称查询id等等...

    /**
     * 针对学员表(student_manage)进行操作
     * 根据学员名称查找其编号
     * @param className 学员名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT class_id FROM class WHERE student_name=#{className}")
    int selectByClassName(@Param("className") String className);

    /**
     * 针对校区表(school)进行操作
     * 根据校区名称查找其编号
     * @param classRoomName 校区名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT classroom_id FROM classRoom WHERE classRoom_name=#{classRoomName}")
    int selectByClassRoomName(@Param("classRoomName") String classRoomName);

    /**
     * 针对课程表(lesson)进行操作
     * 根据课程名称查找其编号
     * @param lessonName 课程名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT lesson_id FROM lesson WHERE lesson_name=#{lessonName}")
    int selectByLessonName(@Param("lessonName") String lessonName);

    /**
     * 针对课程表(lesson)进行操作
     * 根据课程名称查找其编号
     * @param recordName 课程名称
     * @return 影响的行数(>1:成功)
     */
    @Select("SELECT record_id FROM record WHERE record_Name=#{recordName}")
    int selectByRecordName(@Param("recordName") String recordName);
    ////////////////////////////
    // 如下是获取下拉框数据的方法...

    /**
     * 得到所有校区信息
     * @return 校区对象集合
     */
    @Select("select classRoom_id,classRoom_name from classroom")
    @Results({
            @Result(id = true,column = "classRoom_id",property = "classroomId"),
            @Result(column = "classRoom_name",property = "classRoomName")
    })
    List<ClassRoom> selectAllGetClassRoom();

    /**
     * 得到所有课程信息
     * @return 课程对象集合
     */
    @Select("select lesson_id,lesson_name from lesson")
    @Results({
            @Result(id = true,column = "lesson_id",property = "lessonId"),
            @Result(column = "lesson_name",property = "lessonName"),
    })
    List<Lesson> selectAllGetLesson();


    /**
     * 得到所有校区信息
     * @return 校区对象集合
     */
    @Select("select class_id,class_name from class")
    @Results({
            @Result(id = true,column = "class_id",property = "classId"),
            @Result(column = "class_name",property = "className")
    })
    List<Class> selectAllGetClass();

    /**
     * 得到所有课程信息
     * @return 课程对象集合
     */
    @Select("select record_id,record_name from record")
    @Results({
            @Result(id = true,column = "record_id",property = "recordId"),
            @Result(column = "record_name",property = "recordName")
    })
    List<Record> selectAllGetRecord();

}
